from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import os

def generate_launch_description():
    # 动态获取其他工作空间的路径
    other_ws_path = os.path.join(get_package_share_directory('micro_ros_agent'), '/home/ajream/quickDir/microros_ws/install')

    # 手动设置环境变量（覆盖或追加）
    os.environ['AMENT_PREFIX_PATH'] = f"{other_ws_path}:{os.environ.get('AMENT_PREFIX_PATH', '')}"

    return LaunchDescription([
        # 启动当前工作空间的节点
        Node(
            package='trace_visualizer_py',
            executable='trace_visualizer_node'
        ),
        Node(
            package='joystick_read',
            executable='joystick_node'
        ),
        # 启动其他工作空间的节点
        Node(
            package='micro_ros_agent',
            executable='micro_ros_agent',
            arguments=['udp4', '--port', '11888'],  # 传递参数
#            namespace='other_ns'  # 可选：隔离命名空间
        )
    ])
